home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / pas_all.zip / TI555.ASC < prev    next >
Text File  |  1992-05-13  |  3KB  |  133 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Turbo Pascal                           NUMBER  :  555
  9.   VERSION  :  All
  10.        OS  :  Dos
  11.      DATE  :  May 13, 1992                             PAGE  :  1/2
  12.  
  13.     TITLE  :  Network File Access
  14.  
  15.  
  16.  
  17.  
  18.   FILE AND RECORD LOCKING IN TURBO PASCAL
  19.  
  20.   Turbo Pascal does not have built-in support for file and record
  21.   locking.  It does, however, have the ability to open files for
  22.   shared access.  This is accomplished by setting the value of the
  23.   system variable FileMode.  By default, FileMode has a value of 2
  24.   which causes files opened to have single-user, read/write access.
  25.   A shared, read/write mode can be had by setting FileMode to a
  26.   value of 66. Whereas, a shared, read only mode is represented by
  27.   the value 64.
  28.  
  29.   Record and file locking is a bit more difficult.  DOS version 3.0
  30.   and later provide record locking through the use of Interrupt
  31.   21H, Service 5CH.  This service may be accessed through Turbo
  32.   Pascal's procedure MsDos defined in the Dos unit.
  33.  
  34.   Here's a routine designed to lock and unlock portions of any
  35.   untyped or type file.  Note, these routines may not be used with
  36.   text files.
  37.  
  38.   procedure LockBlock(var F; Offset: Longint; Length: LongInt;
  39.   Lock: Boolean);
  40.   type
  41.     LoHiRec = record
  42.      LoWord, HiWord: Word;
  43.     end;
  44.   var
  45.     RecordSize: Word;
  46.     Handle: Integer;
  47.     File: FileRec absolute F;
  48.     R: Registers;
  49.   begin
  50.     Handle := File.Handle;
  51.     RecordSize := File.RecSize;
  52.     Offset := Offset * RecordSize;
  53.     R.CX := LoHiRec(Offset).LoWord;
  54.     R.DX := LoHiRec(Offset).HiWord;
  55.     R.SI := LoHiRec(Length).LoWord;
  56.     R.DI := LoHiRec(Length).HiWord;
  57.     R.AH := $5C;
  58.     if Lock then R.AL := 0 else R.AL := 1;
  59.     MsDos(R);
  60.     if (R.Flags and FCarry) <> 0 then
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Turbo Pascal                           NUMBER  :  555
  75.   VERSION  :  All
  76.        OS  :  Dos
  77.      DATE  :  May 13, 1992                             PAGE  :  2/2
  78.  
  79.     TITLE  :  Network File Access
  80.  
  81.  
  82.  
  83.  
  84.     begin
  85.       RunError(R.AX);
  86.     end;
  87.   end;
  88.  
  89.   The parameter 'offset' indicates what record is to mark the
  90.   beginning of the file lock. 'Length' determines how many records
  91.   will be locked from this point.  The 'lock' parameter determines
  92.   whether the portion of the file is to be locked or unlocked.
  93.  
  94.   To lock an entire file, pass 0 for offset and the results of the
  95.   FileSize function for the number of records to be locked.
  96.  
  97.   This routine will function as expected when using SHARE and/or
  98.   MS-DOS compatible network software.
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.